<template>
  <div class="customers-content-report tag-scrollbar">
    <div class="story-box">
      <div class="story-title linear-blue">
        <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
        运行结果
      </div>
      <div class="story-content">
        <div class="result-title">
          <el-row>
            <el-col :span="3" align="center">
              <span>更新周期</span>
            </el-col>
            <el-col :span="3" align="center">
              <span>运行结果</span>
            </el-col>
            <el-col :span="4" align="center">
              <span>上次运行时间</span>
            </el-col>
            <el-col :span="4" align="center">
              <span>源客群</span>
            </el-col>
            <el-col :span="4" align="center">
              <span>对比客群</span>
            </el-col>
            <el-col :span="3" align="center">
              <span>客群差异度</span>
            </el-col>
            <el-col :span="3" align="center">
              <span>客群相似度</span>
            </el-col>
          </el-row>
        </div>
        <div class="result-content tag-scrollbar">
          <el-row>
            <el-col :span="3" align="center" class="success">
              {{ $dict('$exec_frequency')[tagData.execFrequency] }}
            </el-col>
            <el-col :span="3" align="center" class="success">
              成功
            </el-col>
            <el-col :span="4" align="center">
              {{ tagData.updateTm }}
            </el-col>
            <el-col :span="4" align="center">
              {{ tagData.sourcePortraitName }}
            </el-col>
            <el-col :span="4" align="center">
              {{ tagData.contrastPortraitName }}
            </el-col>
            <el-col :span="3" align="center" class="success">
              {{ tagData.diffValue }}
            </el-col>
            <el-col :span="3" align="center" class="success">
              {{ tagData.simValue }}
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <div class="story-box tag-story">
      <div class="story-title linear-orange">
        备注
      </div>
      <div class="story-content story-text">
        <el-input type="textarea" :rows="4" disabled v-model="tagData.tagStory" resize="none"></el-input>
      </div>
    </div>
    <div class="diff-top">
      <div class="title-box clearfix">
        <span class="title-text">客群差异性分析</span>
        <el-select v-model="diffTop" value-key="topNum" size="small">
          <el-option
            v-for="item in diffTopList"
            :key="item.topNum"
            :value="item"
            :label="`TOP${item.topNum}-${item.tagName}`"
          ></el-option>
        </el-select>
      </div>
      <diff-top v-if="diffTop" :topData="diffTop" type="diff"></diff-top>
    </div>
    <div class="sim-top">
      <div class="title-box clearfix">
        <span class="title-text">客群相似性分析</span>
        <el-select v-model="simTop" value-key="topNum" size="small">
          <el-option
            v-for="item in simTopList"
            :key="item.topNum"
            :value="item"
            :label="`TOP${item.topNum}-${item.tagName}`"
          ></el-option>
        </el-select>
      </div>
      <sim-top v-if="simTop" :topData="simTop" type="sim"></sim-top>
    </div>
    <div class="table-box">
      <div class="title-box clearfix">
        <span class="title-text">详细数据报表</span>
        <el-button type="primary" size="small" @click="downloadData" :disabled="!tagData.fileId">下载数据</el-button>
      </div>
      <tag-table
        ref="table"
        :data="dataList"
        :columns="columns"
        :spanMethod="spanMethod"
        :pagination="false"
      ></tag-table>
    </div>
  </div>
</template>

<script>
import topItem from './content-report-top-item'
export default {
  components: {
    diffTop: topItem,
    simTop: topItem
  },
  data() {
    return {
      tagData: {},
      diffTopList: [],
      diffTop: '',
      simTopList: [],
      simTop: '',
      dataList: [],
      columns: [
        {
          show: true,
          label: '标签名',
          prop: 'tagNm',
          align: 'center'
        },
        {
          show: true,
          label: '区间范围/值',
          prop: 'tgiName',
          align: 'center'
        },
        {
          show: true,
          label: '差异性程度',
          prop: 'diffValue',
          align: 'center'
        },
        {
          show: true,
          label: '相似性程度',
          prop: 'simValue',
          align: 'center'
        },
        {
          show: true,
          label: '源画像TGI',
          prop: 'sourceToComparTGI',
          align: 'center'
        },
        {
          show: true,
          label: '对比客群TGI',
          prop: 'comparToSourceTGI',
          align: 'center'
        },
        {
          show: true,
          label: 'CTGI',
          prop: 'diffEffectValueTGI',
          align: 'center'
        }
      ]
    }
  },
  methods: {
    setData(data) {
      this.tagData = data
      this.setTopList()
      this.setDataList(this.tagData.detailedDataReport)
    },
    setTopList() {
      let diffList = this.tagData.diffPreviewResults.map((item, index) => {
        return Object.assign(
          {
            topNum: index + 1,
            sourcePortraitName: this.tagData.sourcePortraitName,
            contrastPortraitName: this.tagData.contrastPortraitName
          },
          item
        )
      })
      let simList = this.tagData.simPreviewResults.map((item, index) => {
        return Object.assign(
          {
            topNum: index + 1,
            sourcePortraitName: this.tagData.sourcePortraitName,
            contrastPortraitName: this.tagData.contrastPortraitName
          },
          item
        )
      })
      this.diffTopList = diffList
      this.diffTop = this.diffTopList[0] || ''
      this.simTopList = simList
      this.simTop = this.simTopList[0] || ''
    },
    setDataList(list) {
      let dataList = []
      list.forEach(item => {
        item.tgiName.forEach((data, index) => {
          dataList.push({
            tagNm: item.tagNm,
            tgiName: data,
            diffValue: item.diffValue,
            simValue: item.simValue,
            sourceToComparTGI: item.sourceToComparTGI[index],
            comparToSourceTGI: item.comparToSourceTGI[index],
            diffEffectValueTGI: item.diffEffectValueTGI[index],
            $combine: index === 0 ? item.tgiName.length : 0
          })
        })
      })
      this.dataList = dataList
    },
    spanMethod({ row, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 2 || columnIndex === 3) {
        if (row.$combine) {
          return {
            rowspan: row.$combine,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
    downloadData() {
      if (this.tagData.fileId) {
        this.$dlFile(this.tagData.fileId)
      }
    }
  }
}
</script>

<style lang="scss">
.tag-customers {
  .customers-content-report {
    height: calc(100% - 50px);
    padding-right: 10px;
    overflow-y: auto;
    .story-box {
      margin-top: 5px;
      height: 160px;
      border-radius: 5px;
      box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
      overflow: hidden;
      position: relative;
      &.tag-story {
        height: 120px;
        margin-bottom: 20px;
      }
      .story-title {
        font-size: 15px;
        font-weight: bold;
        width: 150px;
        height: 100%;
        color: #fff;
        text-align: center;
        position: relative;
        &:before {
          width: 100%;
          height: 100%;
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          background: url(~@/assets/img/params_bg.png) no-repeat 0px 0px/100% 100%;
        }
        .icon {
          display: inline-block;
          width: 80px;
          height: 80px;
          background-color: #fff;
          margin: 30px 0 10px;
          border-radius: 50%;
          svg {
            width: 50px;
            height: 50px;
            margin-top: 15px;
          }
        }
      }
      .linear-orange {
        background: linear-gradient(to bottom, #f3bf7c, #f3b172);
        line-height: 120px;
        font-size: 16px;
      }
      .linear-blue {
        background: linear-gradient(to bottom, #63a3fc, #5188ec);
        svg {
          color: #5188ec;
        }
      }
      .story-content {
        padding-left: 150px;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        .result-title {
          height: 50px;
          border-bottom: 1px solid #eee;
          font-weight: bold;
          span {
            display: inline-block;
            width: 80%;
            height: 40px;
            line-height: 40px;
            margin: 5px 0;
            background-color: #fcf5e5;
            border-radius: 20px;
          }
        }
        .result-content {
          font-size: 20px;
          font-weight: bold;
          margin-top: 45px;
          .el-col {
            min-height: 1px;
          }
          .success {
            color: #04bf55;
          }
        }
      }
      .story-text {
        padding: 13px 13px 13px 165px;
        .el-textarea.is-disabled .el-textarea__inner {
          color: #666;
          cursor: default;
          height: 100%;
        }
      }
    }
    .title-box {
      line-height: 32px;
      font-size: 22px;
      font-weight: bold;
      margin-bottom: 10px;
      .title-text {
        float: left;
      }
      .el-button {
        float: right;
      }
      .el-select {
        float: left;
        margin-left: 10px;
      }
    }
  }
}
</style>
